import React,{ Component } from "react";
import ChildComponet from './childComponent'

class ParentComponent extends Component{
  constructor(props){
    super(props)
    this.state = {
      message:'hello from parent'
    }

    this.sendMessageToChild = this.sendMessageToChild.bind(this)
  }

  sendMessageToChild(newMessage){
    this.setState({
      message: newMessage
    })
  }
  render (){
    return (
      <div>
        <h1>父组件</h1>
        <ChildComponet parentMessage={this.state.message} sendMessage={this.sendMessageToChild}/>
      </div>
    )
  }
}

export default ParentComponent